﻿using System;
using System.Diagnostics;
using Bookvar.ApplicationModel;
using Bookvar.Collaboration;

namespace BookvarWpf.Windows.Collaboration
{
    /// <summary>
    /// Interaction logic for CollaborationUsersList.xaml
    /// </summary>
    public partial class CollaborationUsersList
    {
        private readonly ICollaborationManager collaborationManager;

        public CollaborationUsersList()
        {
            InitializeComponent();
            collaborationManager = BookvarApplication.Current.ServiceLayer.GetService<ICollaborationManager>();
            Debug.Assert(collaborationManager != null);

            DataContext = collaborationManager.CollaborationUsers;

            collaborationManager.CollaborationStopped += OnCollaborationStopped;
        }

        private void OnCollaborationStopped(object sender, EventArgs e)
        {
            Close();
        }

        public new void Close()
        {
            collaborationManager.CollaborationStopped -= OnCollaborationStopped;

            CloseCommand.Execute(null, this);
        }
    }
}